window.onload = function() {
	seajs.use(['jquery-1.8.2.js', 'iscroll_module.js', 'mdialog_module.js', 'util_module.js'], function(Z, I, M, U) {
		var curPage = 1;
		var pageSize = 4;
		var totalPage = 0;
		U.fillHead();
		U.fillFooter();
		initPage();
		function initPage() { //初始化页面
			U.loadOpt(false);
			U.ajaxget("/person/detail/" + U.getParam("id"), {}, function(json) {
				if(json.success) {
					var personVO = json.models.personVO;
					var headImage = "../images/temp/icon_touxiang1.png";
					if(U.getImg(personVO.headImage).length > 0) {
						headImage = U.getImg(personVO.headImage)[0];
					}
					$(".helper_info .head_img>div:first-child img").attr("src", personVO.headImage);
					$(".helper_info .head_img>div:last-child>div:first-child>span:first-child").text(personVO.name);
					$(".helper_info .head_img>div:last-child>div:first-child>span:nth-child(2)").text(personVO.sex == 1 ? "女" : "男");
					$(".base_info .address").text(personVO.address);
					$(".base_info .city").text(personVO.city);
					$(".base_info .helpArea").text(personVO.helpArea);
					$(".base_info .requirement").text(personVO.requirement);
					$(".base_info .remark").text(personVO.remark);
					$(".wixin").text(personVO.weixin);
					$(".phone").text(U.formPhone(personVO.mobile)); //手机号码
				} else {
					M.toast(false, json.errorMsg);
				}
			});
			getlist();
		}

		function initEvent() {
			$(".poor_list .poor_details").unbind("click").click(function() {
				U.laodPoor_view(true, {
					"id": $(this).attr("id")
				});
			});
		}

		function getlist() {
			U.loadOpt(true);
			$(".poor_list").empty();
			U.ajaxget("/poverty/list/" + U.getParam("userId"), {}, function(json) {
				U.loadOpt(false);
				if(json.success) {
					$(json.models.povertyObjList).each(function() {
						var poor = "<div><div class='poor_name'>" + this.name + "</div><div class='poor_address'><span>住址：</span><span>" + this.address + "</span></div><div class='poor_reason'><span>致贫原因：</span><span>" + this.reason + "</span></div><span class='poor_details' id='" + this.id + "'>详情</span></div>";
						$(".poor_list").append(poor);
					});
					initEvent();
				} else {
					M.toast(false, json.errorMsg);
				}
			});
		}
	});
}